<!DOCTYPE >
<html lang="zh-cn">
<head>
		<title>后台管理-功能</title>
    <% include ../partials/head %>
    <script type="text/javascript">
    var oArticle ={
        operator:function(){
            $(".box-content").on("click",".public",function(){
                $this = $(this)
                if(window.confirm('你确定发布该文章么？')){
                    $.post("/admin/article/publish",{
                        "objectId":$this.attr('articleId'),
                    },function(json){
                        if(json.code==0){
                            history.go(0);
                        }else{
                            alert(json.msg);
                        }
                    },'json');
                }else{
                    //取消
                }
            }).on("click",".reEdit",function(){
                $this = $(this)
                if(window.confirm('你确定将文章改为编辑状态么？')){
                    $.post("/admin/article/resume",{
                        "objectId":$this.attr('articleId'),
                    },function(json){
                        if(json.code==0){
                            history.go(0);
                        }else{
                            alert(json.msg);
                        }
                    },'json');
                }else{
                    //取消
                }
            }).on("click",".cancel",function(){
                $this = $(this)
                if(window.confirm('你确定下架该文章么？')){
                    $.post("/admin/article/disable",{
                        "objectId":$this.attr('articleId'),
                    },function(json){
                        if(json.code==0){
                            history.go(0);
                        }else{
                            alert(json.msg);
                        }
                    },'json');
                }else{
                    //取消
                }
            }).on("click",".delete",function(){
                $this = $(this)
                if(window.confirm('你确定要删除该文章么？')){
                    $.post("/admin/article/delete",{
                        "objectId":$this.attr('articleId'),
                    },function(json){
                        if(json.code==0){
                            history.go(0);
                        }else{
                            alert(json.msg);
                        }
                    },'json');
                }else{
                    //取消
                }
            })
        },
        change:function(){
            var state =window.location.href.split("=")[1];
            $("#article-filter option[value='"+state+"']").attr("selected","selected");
            $("#article-filter").on("change",function(){
                var value = $(this).children('option:selected').val(); 
                window.location.href="/admin/article?status="+value;
            })
        },
        init:function(){
            this.operator();
            this.change();
        }
    }
    $(document).ready(function(){
        oArticle.init();
    })
    </script>
</head>
<body>
	<header>
    <% include ../partials/header %>
  </header>
  <div class="ch-container">
    <div class="row">
      <% include ../partials/sidebar %>
      <!-- 页面内容 -->
      <div id="content" class="col-lg-10 col-sm-10">
        <div class="row">
          <div class="box col-md-12">
            <div class="box-inner">
              <div class="box-header well" data-original-title="">
                <div class="control-group">
                  <div class="controls">
                    <label class="control-label" for="selectError">筛选:&nbsp&nbsp&nbsp </label>
                    <select id="article-filter" >
                        <option value="0">正在编辑</option>
                        <option value="1">已发布</option>
                        <option value="2">已下架</option>
                    </select>
                    <a class="btn btn-default pull-right" href="/admin/article/add" >
                     <i class="glyphicon glyphicon-plus green"></i> 新建文章
                   </a>
                  </div>
                  
                </div>
              </div>

              <div class="box-content">
                <table class="table table-striped table-bordered bootstrap-datatable datatable responsive">
                  <thead>
                    <tr>
                      <th>标题</th>
                      <th>所属专题</th>
                      <th>创建时间</th>
                      <th>喜欢数</th>
                      <th>分享数</th>
                      <th>评论数</th>
                      <th>阅读数</th>
                      <th>网址</th>
                      <th>处理</th>
                    </tr>
                  </thead>

                  <tbody>
                    <% if (typeof articles != "undefined") { %>
                      <% articles.forEach(function(article) { %>
                        <tr>
                          <td class="center"><%= article.get("title") %></td>
                          <td class="center"><%= article.get("topic")? article.get("topic").get("title"):"" %></td>
                          <td class="center"><%= Format(article.createdAt) %></td>
                          <td class="center"><%= article.get("likeCount") %></td>
                          <td class="center"><%= article.get("shareCount") %></td>
                          <td class="center"><%= article.get("commentCount") %></td>
                          <td class="center"><%= article.get("readCount") %></td>
                          <td class="center"><a href="<%= article.get("address") %>"><%= article.get("address") %></a></td>
                          <td class="center">
                            <% if(article.get("status")==1){ %>
                                <a class="btn btn-info" href="/admin/article/edit?objectId=<%=article.id %>">
                                      <i class="glyphicon glyphicon-zoom-in icon-white"></i>
                                     编辑 
                                  </a> 
                                <span class="btn btn-danger cancel" articleId=<%=article.id%>>
                                  <i class="glyphicon glyphicon-minus-sign icon-white"></i>
                                 下架 
                                </span>   
                            <% } %>
                            <% if(article.get("status")==2){ %>
                                <span class="btn btn-default reEdit" articleId=<%=article.id%>>
                                  <i class="glyphicon glyphicon-edit icon-white"></i>
                                 改为编辑状态 
                                </span> 
                            <% } %>
                            <% if(article.get("status")==0){ %>
                                  <a class="btn btn-info" href="/admin/article/edit?objectId=<%=article.id %>">
                                      <i class="glyphicon glyphicon-zoom-in icon-white"></i>
                                     编辑 
                                  </a> 
                                  <span class="btn btn-success public" articleId=<%=article.id%>>
                                      <i class="glyphicon glyphicon-ok icon-white"></i>
                                     发布
                                    </span> 
                                  <span class="btn btn-danger delete" articleId=<%=article.id%>>
                                      <i class="glyphicon glyphicon-remove icon-white"></i>
                                     删除 
                                  </span>  
                            <% } %>
                          </td>
                        </tr>
                      <% }) %>
                    <% } %>
                  </tbody>
                </table>
              </div>

            </div>
          </div>
        </div>
      </div>
    </div>
    <% include ../partials/footer %>
  </div>
  <% include ../partials/external %>
</body>
</html>
